# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=snort
pkgver=2.9.20
_pkgver=2.9.20
pkgrel=2
pkgdesc='A lightweight network intrusion detection system.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-defensive' 'blackarch-networking'
        'blackarch-forensic' 'blackarch-ids')
url='http://www.snort.org/'
license=('GPL')
depends=('libdaq' 'libdnet' 'libpcap' 'openssl' 'pcre' 'zlib' 'libutil-linux'
         'libtirpc' 'luajit')
makedepends=('ca-certificates')
backup=('etc/conf.d/snort'
        'etc/snort/snort.conf'
        'etc/snort/threshold.conf'
        'etc/snort/reference.config'
        'etc/snort/classification.config')
options=('!makeflags' '!libtool')
source=("https://www.snort.org/downloads/snort/$pkgname-$_pkgver.tar.gz"
        'http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz'
        'snort'
        'snort.conf.d'
        'snort.service')
sha512sums=('a9ca37e814baeb978a6db06c3c62256b9e98fdd9fa18ce881a2ce854c0c9a5d92476c3384bec9017b8a67e5d78c6f31ca19956a914f54b817343a159a2a7fced'
            '4e9ea8d25e526dd1f92aac6c80db6823c0cedf99b3d904831d9d2fbc930fa7e7b40c9bce3c808f663e133227a96cfa471914547bfc2b55a2798d418d6fc1da33'
            '96d3a27752c60cec9b188cdc358f3a38c0f6f0a179e16f3778abaf6385cc82169cdf0b41ea9bf39cfa64455e6ca5e484c2d952c72ced0901512b4750343ec5d9'
            '08341de9f302622b40917914e5e67c0f79c1800c463be7675bb019a3c033c3302a1be522ffd7a5b4759211f962ce4557557ea2653c4c89843dbd33b95a2e2e35'
            'cee2e637f98ffa31dfd1a34c955372f93fb3c3f75fcf224d8ecf4c668a2ff20ed0c1d75e7e3028665cee675ae4b160d3ba7c222bfdb453310d1e5028ac414eea')
install="$pkgname.install"

prepare() {
  cd "$pkgname-$_pkgver"

  autoreconf -fi
}

build() {
  cd "$pkgname-$_pkgver"

  CPPFLAGS="$CPPFLAGS -I/usr/include/tirpc/" ./configure --prefix=/usr \
    --sysconfdir="/etc/$pkgname" --with-libpcap-includes=/usr/include/pcap \
    --with-daq-includes=/usr/include --with-daq-libraries=/usr/lib/daq \
    --disable-static-daq --enable-zlib --enable-sourcefire --enable-large-pcap \
    --enable-64bit-gcc --enable-linux-smp-stats --enable-large-pcap

  make
}

package() {
  cd "$pkgname-$_pkgver"

  make DESTDIR="$pkgdir" install

  install -dm 755 "$pkgdir/etc/rc.d"
  install -dm 755 "$pkgdir/etc/$pkgname/rules"
  install -dm 755 "$pkgdir/var/log/snort"

  install -Dm 644 etc/{*.conf*,*.map} "$pkgdir/etc/$pkgname/"
  install -Dm 644 "$srcdir/snort.conf.d" "$pkgdir/etc/conf.d/$pkgname"
  install -Dm 755 "$srcdir/snort" "$pkgdir/etc/rc.d/$pkgname"

  install -Dm 644 ../snort.service \
    "$pkgdir/usr/lib/systemd/system/snort@.service"

  sed -i 's#/usr/local/lib/#/usr/lib/#' "$pkgdir/etc/$pkgname/snort.conf"

  # Emerging threats rules.
  echo 'include $RULE_PATH/emerging.conf' >> "$pkgdir/etc/$pkgname/snort.conf"
  cp "$srcdir/rules/"* "$pkgdir/etc/$pkgname/rules"
}

